The following example exports a simple IDL object that has no properties or methods and demonstrates the configuration necessary to initialize a COM or Java client application to use the exported object. First, create the IDL source object.
FUNCTION helloworld::INIT
RETURN, 1
END
PRO helloworld__define
struct = {helloworld, $
dummy:0b $ ; dummy structure field, not a property
}
END
This is the source object definition file that you will export using the Export Bridge Assistant.
The following example exports and uses the helloworld object in a simple Visual Basic .NET console application. After creating the object definition file and launching the Assistant as described in Wrapper Generation Example, complete the following steps.
helloworld__define.pro file. Click Open to load the file into the Export Assistant.
There is no need to modify the default properties shown in the right-hand property panel, but you can enter different values if desired. Select the tree view item listed in the left column to configure the related properties in the right column.
|
Tree View Item |
Parameter Configuration |
|---|---|
|
IDL Export Bridge Project |
Accept the default value or make changes as desired:
|
|
helloworld |
Drawable object equals False |
For this simple example, the source object has no properties or methods, so none are exported.
Note: See Specifying Information for Exporting for details on configuring export values.
.tlb and .dll files (named based on the object name) are created in the Output directory..dll using regsvr32 helloworld.dll. See COM Registration Requirements for details if needed.helloworldLib 1.0 Type Library. Select Project > Add Reference, and click on the COM tab. Select the helloworld.dll and click OK.Imports helloworldLib
Module Module1
Dim oHello As New helloworldLib.helloworldClass
Sub Main()
Try
oHello.CreateObject(0, 0, 0)
Catch ex As Exception
Console.WriteLine(oHello.GetLastError())
Return
End Try
AddHandler oHello.OnIDLOutput, AddressOf evOutput
oHello.ExecuteString("Print, 'Hello World'")
End Sub
Sub evOutput(ByVal ss As String)
Console.WriteLine(ss)
End Sub
End Module
In this example, the stock ExecuteString method is used to print the hello world message. By adding a handler for the OnIDLOutput method, the console application is able to capture and output the information that would typically be printed to the Output window of IDL. After building the solution and starting without debugging, the console window appears with the output messages.
The following example exports and uses the helloworld object in a simple Java application. After creating the object definition file and launching the Assistant as described in Wrapper Generation Example, complete the following steps.
helloworld__define.pro file. Click Open to load the file into the Export Assistant.
There is no need to modify the default properties shown in the right-hand property panel, but you can enter different values if desired. Select the tree view item listed in the left column to configure the related properties in the right column.
|
Tree View Item |
Parameter Configuration |
|---|---|
|
IDL Export Bridge Project |
Accept the default value or make changes:
|
|
helloworld |
Drawable object equals False |
For this simple example, the source object has no properties or methods, so none are exported.
Note: See Specifying Information for Exporting for details on configuring export values.
.java and .class files, and is located in the Output directory.helloworld_example.java that contains the following code and save the file in the helloworld directory.package helloworld;
import com.idl.javaidl.*;
public class helloworld_example extends helloworld implements JIDLOutputListener
{
private helloworld hwObj;
// Constructor
public helloworld_example()
{
hwObj = new helloworld();
hwObj.createObject();
hwObj.addIDLOutputListener(this);
hwObj.executeString("print, 'Hello World'");
}
// implement JIDLOutputListener
public void IDLoutput(JIDLObjectI obj, String sMessage)
{
System.out.println("IDL: "+sMessage);
}
public static void main(String[] argv)
{
helloworld_example example = new helloworld_example();
}
}
Note: By default, the Assistant generates a package so any Java routine using an exported wrapper object must include the package name. The second statement, import com.idl.javaidl.*; is also required.
The wrapper is compiled and run using the commands below:
The following commands build and run this Java wrapper example on Windows.
cmd in the textbox.cd command to change to the directory containing the helloworld directory. For a default Windows installation, the command would be similar to the following:cd C:\ITT\IDL63
javaidlb.jar in the compile statement. Enter the following commands (each as a single line), replacing IDL_DIR with the IDL installation directory, for example ITT\IDL63:javac -classpath ".;IDL_DIR\resource\bridges\export\java\javaidlb.jar" helloworld\helloworld_example.java
java -classpath ".;IDL_DIR\resource\bridges\export\java\javaidlb.jar" helloworld.helloworld_example
In both commands, the . (period) character includes the current directory in the classpath.
The first command uses javac to compile the example client. The path to the helloworld_example.java file is specified using a backslash character as a directory separator.
The second command uses java to run the example client. The final argument specifies the package path to the helloworld_example class file. Note that a . (period) character is used as a separator in the package path. The final argument to the second command intentionally omits the suffix.
After compiling and running the project, the output message will appear in the command window.
The following commands build and run this Java wrapper example on UNIX:
source IDL_DIR/bin/bridge_setup
javac helloworld/helloworld_example.java
java helloworld.helloworld_example
Note: See Java Requirements for more information on the bridge_setup file.
The source command adds the necessary directories to the dynamic library path and the classpath.
The second command uses javac to compile the example client. The third command uses java to run the example client. The final argument specifies the package path to the helloworld_example. class file. Note that a . (period) character is used as a separator in the package path. The final argument to the second command intentionally omits the suffix.
After compiling and running the project, the output message will appear.